﻿using CoreModule;
using Prism.Ioc;
using System.Windows;
using System.Windows.Controls;
namespace IdResourceModule.Views
{
    /// <summary>
    /// 通用配置界面
    /// </summary>
    public partial class ConfigurationHome : Window
    {
        IContainerProvider ContainerProvider { get; set; }
        public ConfigurationHome(IContainerProvider containerProvider)
        {
            InitializeComponent();
            ContainerProvider = containerProvider;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
             
            this.Close();
        }
      
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
           var deviceConfigurationInfo = this.cbHis.SelectedItem as DeviceConfigurationInfo;
            if (deviceConfigurationInfo==null)
            {
                return;
            }
            if (deviceConfigurationInfo.HasConfiguration)
            {
                    var window = ContainerProvider.Resolve<Window>(deviceConfigurationInfo.DeviceName);
                    if (window != null)
                    {
                        window.ShowDialog();
                    }
                else
                {
                    MessageBox.Show("belum dikonfigurasi", "Message Tip");
                }
                }
            
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbHis_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            var deviceConfigurationInfo = this.cbHis.SelectedItem as DeviceConfigurationInfo;
            if (deviceConfigurationInfo == null)
            {
                return;
            }
            if (btnEdit != null)
            {
                btnEdit.Visibility = deviceConfigurationInfo.HasConfiguration ? Visibility.Visible : Visibility.Collapsed;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbHis_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var deviceConfigurationInfo = this.cbHis.SelectedItem as DeviceConfigurationInfo;
            if (deviceConfigurationInfo == null)
            {
                return;
            }
            if (deviceConfigurationInfo.HasConfiguration)
            {
                var window = ContainerProvider.Resolve<Window>(deviceConfigurationInfo.DeviceName);
                if (window != null)
                {
                    window.ShowDialog();
                }
                else
                {
                    MessageBox.Show("belum dikonfigurasi", "Message Tip");
                }
            }
        }
        private void lstRecognitionDevice_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
           
            var deviceConfigurationInfo = lstRecognitionDevice.SelectedItem as DeviceConfigurationInfo;
             
            if (deviceConfigurationInfo == null)
            {
                return;
            }
            if (deviceConfigurationInfo.HasConfiguration)
            {
                var window = ContainerProvider.Resolve<Window>(deviceConfigurationInfo.DeviceName);
                if (window != null)
                {
                    window.ShowDialog();
                }
                else
                {
                    MessageBox.Show("belum dikonfigurasi", "Message Tip");
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RecognitionDevice_Click(object sender, RoutedEventArgs e)
        {
            var btn = sender as Button;
           var deviceConfigurationInfo= btn.Tag as DeviceConfigurationInfo;
            if (deviceConfigurationInfo == null)
            {
                return;
            }
            if (deviceConfigurationInfo.HasConfiguration)
            {
                var window = ContainerProvider.Resolve<Window>(deviceConfigurationInfo.DeviceName);
                if (window != null)
                {
                    window.ShowDialog();
                }
                else
                {
                    MessageBox.Show("belum dikonfigurasi", "Message Tip");
                }
            }
             
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var deviceConfigurationInfo = this.cbHis.SelectedItem as DeviceConfigurationInfo;
            if (deviceConfigurationInfo == null)
            {
                return;
            }
            if (btnEdit != null)
            {
                btnEdit.Visibility = deviceConfigurationInfo.HasConfiguration ? Visibility.Visible : Visibility.Collapsed;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSetDb_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            DbHome db = new DbHome();
            db.ShowDialog();
        }

        private void btnSetDb_Click(object sender, RoutedEventArgs e)
        {
            DbHome db = new DbHome();
            db.ShowDialog();
        }
    }
}
